"""
帮助命令
"""
import click
from i18n import t


def get_help_text() -> str:
    return t("help.main")


@click.command()
@click.argument("command", required=False)
@click.pass_context
def help(ctx, command):
    """显示帮助信息"""
    if command:
        parent_ctx = ctx.parent
        if parent_ctx:
            cmd = parent_ctx.command.get_command(parent_ctx, command)
            if cmd:
                click.echo(cmd.get_help(parent_ctx))
            else:
                click.echo(t("help.unknown_command", command=command), err=True)
                click.echo(parent_ctx.get_help())
        else:
            click.echo(t("help.no_parent_context"), err=True)
    else:
        click.echo(get_help_text())

